from selenium.webdriver import Chrome
from selenium.webdriver.common.keys import Keys
import time


# 1.创建浏览器
web = Chrome()
# 2.打开网址
web.get("https://lagou.com")

# print(web.title)
el = web.find_element('xpath', '//*[@id="changeCityBox"]/ul/li[1]/a')
# 点击事件，选择地区
el.click()

# 让浏览器加载一段时间
time.sleep(2)
# 找到输入框
edit = web.find_element('xpath', '//*[@id="search_input"]')
edit.send_keys('python', Keys.ENTER)

# 让浏览器加载一段时间
time.sleep(3)
# 爬取数据
divList = web.find_elements('xpath', '//*[@id="jobList"]/div[1]/div')
for div in divList:
    jobName = div.find_element('xpath', './/*[@id="openWinPostion"]').text
    salary = div.find_element('xpath', './/*[@class="money__3Lkgq"]').text
    print(jobName, salary)


input()